package jinyilw.swing.visuals.comp;

import jinyilw.swing.ResourceManager;

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.net.URL;

public class ImageComp extends MouseActComp
{
	private static final long serialVersionUID = -1276675463020135887L;
	protected Image image;

	public ImageComp()
	{
	}

	public ImageComp(Image img)
	{
		image = img;
	}

	public void setImage(Image img)
	{
		if (image != img)
		{
			image = img;
			if (isShowing())
				repaint();
		}
	}

	public void setImage(URL url)
	{
		setImage(ResourceManager.getBufferedImage(url));
	}

	public void setImage(File file)
	{
		setImage(ResourceManager.getBufferedImage(file));
	}

	public Image getImage()
	{
		return image;
	}

	public boolean isBlank()
	{
		return image == null;
	}

	@Override
	public void paint(Graphics g)
	{
		if (image != null)
			g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
	}

	public void clearImage()
	{
		image = null;
		if (isShowing())
			repaint();
	}
}
